<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>添加商品页面</h1>
    <input type="text" v-model="p.title" placeholder="商品标题">
    <input type="text" v-model="p.price" placeholder="商品价格">
    <input type="text" v-model="p.num" placeholder="商品库存">
    <input type="button" value="添加" @click="add()">
</div>
<!--引入axios和vue框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<script>
    let v = new Vue({
        el: "body>div",
        data: {
            p:{title:"",price:"",num:""}
        },
        methods: {
            add(){
                //发出异步post
                axios.post("/insert",v.p).then(function (response) {
                    alert("添加完成!");
                    location.href="/"; //显示首页
                })
            }
        }
    })
</script>
</body>
</html>